import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

const router = new Router({
  mode: 'history',
  base: process.env.BASE_URL,
  routes: [
    { 
      path: '/',
      redirect: '/layout'
    },
    { 
      path: '/login',
      name:'登录',
      meta:{
        title:'登录'
      },
      component:()=> import("@/views/login") 
    },
    {
      path:'/layout',
      name:'首页',
      component:()=>import("@/layout"),
      redirect:'/home',
      children:[
        {
          id:0,
          path:'/home',
          name:'经营大数据',
          component:()=>import("@/views/home")
        },
        {
          id:7,
          path:'/shopClass',
          name:'商品分类',
          component:()=>import("@/views/manageShop/shopClass"),
        },
        {
          id:8,
          path:'/shopDisc',
          name:'折扣商品',
          component:()=>import("@/views/manageShop/shopDisc"),
        },
        {
          id:9,
          path:'/onOffShopaddShop',
          name:'上下架商品',
          component:()=>import("@/views/manageShop/onOffShopaddShop"),
        },
        {
          id:10,
          path:'/members',
          name:'普通会员',
          component:()=>import("@/views/memberManage/members"),
        },
        {
          id:11,
          path:'/HeaderManage',
          name:'团长管理',
          component:()=>import("@/views/memberManage/HeaderManage"),
        },
        {
          id:12,
          path:'/commitManage',
          name:'班委管理',
          component:()=>import("@/views/memberManage/commitManage"),
        },
        {
          id:13,
          path:'/customOrder',
          name:'客户订单列表',
          component:()=>import("@/views/manageOrder/customOrder"),
        },
        {
          id:14,
          path:'/customRefund',
          name:'客户退款列表',
          component:()=>import("@/views/manageOrder/customRefund"),
        },
        {
          id:15,
          path:'/orderPlat',
          name:'订单列表(平台)',
          component:()=>import("@/views/manageOrder/orderPlat"),
        },
        {
          id:16,
          path:'/orderHeader',
          name:'订单列表(团长)',
          component:()=>import("@/views/manageOrder/orderHeader"),
        },
        {
          id:17,
          path:'/marketList',
          name:'营销列表',
          component:()=>import("@/views/centerMarket/marketList"),
        },
        {
          id:18,
          path:'/galleryList',
          name:'展厅列表',
          component:()=>import("@/views/centerMarket/galleryList"),
        },
        {
          id:19,
          path:'/noGalleryList',
          name:'非展厅列表',
          component:()=>import("@/views/centerMarket/noGalleryList"),
        },
        {
          id:20,
          path:'/dataList',
          name:'数据列表',
          component:()=>import("@/views/centerData/dataList"),
        },
        {
          id:21,
          path:'/cadreScale',
          name:'干部规模',
          component:()=>import("@/views/centerData/cadreScale"),
        },
        {
          id:22,
          path:'/earnData',
          name:'收益数据',
          component:()=>import("@/views/centerData/earnData"),
        },
        {
          id:23,
          path:'/fenceConfig',
          name:'围栏配置',
          component:()=>import("@/views/configSys/fenceConfig"),
        },
        {
          id:24,
          path:'/smsConfig',
          name:'短信平台配置',
          component:()=>import("@/views/configSys/smsConfig"),
        },
        {
          id:25,
          path:'/serverConfig',
          name:'服务器配置',
          component:()=>import("@/views/configSys/serverConfig"),
        },
      ]
    },
    {
      path: '/error404',
      name:'页面路径不存在',
      component:()=>import("@/views/404")
    },
    {
      path: '*',
      name: '404',
      redirect: '/error404'
    }
  ]
})

router.beforeEach((to,from,next) => {
  if(to.path === '/login') return next();
  const tokenStr = window.sessionStorage.getItem('token')
  if(!tokenStr) return next('/login')
  next()
})

export default router
